package com.hicorp.segment.service.impl;

import com.hicorp.segment.mapper.BackendApiMapper;
import com.hicorp.segment.pojo.po.BackendApi;
import com.hicorp.segment.service.BackendApiService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Slf4j
@Service
public class BackendApiServiceImpl implements BackendApiService {
    @Resource
    private BackendApiMapper backendApiMapper;

    /**
     * 初始化数据库中的后端接口
     *
     * @param backendApiList 从backend-api.json中读取到的后端接口.
     */
    @Override
    public void backendApiInit(List<BackendApi> backendApiList) {
        Date date = new Date();
        // 清空backendApi
        backendApiMapper.truncateBackendApi();
        // 录入新的backendApi
        backendApiMapper.insertList(backendApiList.stream().peek(backendApi -> backendApi.setCreateGmt(date)).collect(Collectors.toList()));
    }

}
